package com.zy.qudadid.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zy.lcpassenger.R;
import com.zy.qudadid.model.StrokeBean;
import com.zy.qudadid.presenter.StrokePresenter;
import com.zy.qudadid.ui.activity.base.ToolBarActivity;
import com.zy.qudadid.ui.view.StrokeView;
import com.zy.qudadid.utils.AESCrypt;
import com.zy.qudadid.utils.Bun;
import com.zy.qudadid.utils.StringUtil;
import com.zy.qudadid.utils.UserUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by ASUS on 2017/2/17.
 */

public class StrokeActivity extends ToolBarActivity<StrokePresenter> implements StrokeView {

    @Bind(R.id.rl_rent_car)
    RelativeLayout rlRentCar;
    @Bind(R.id.tv_rentCar_departure)
    TextView tvRentCarDeparture;
    @Bind(R.id.tv_rentCar_destination)
    TextView tvRentCarDestination;
    @Bind(R.id.tv_rentCar_time)
    TextView tvRentCarTime;

    @Bind(R.id.rl_net_car)
    RelativeLayout rlNetCar;
    @Bind(R.id.tv_netCar_departure)
    TextView tvNetCarDeparture;
    @Bind(R.id.tv_netCar_destination)
    TextView tvNetCarDestination;
    @Bind(R.id.tv_netCar_time)
    TextView tvNetCarTime;
    @Bind(R.id.rl_downwind_car)
    RelativeLayout rlDownwindCar;
    @Bind(R.id.tv_downwindCar_departure)
    TextView tvDownwindCarDeparture;
    @Bind(R.id.tv_downwindCar_destination)
    TextView tvDownwindCarDestination;
    @Bind(R.id.tv_downwindCar_time)
    TextView tvDownwindCarTime;

    @Bind(R.id.tv_noRentOrder)
    TextView tv_noRentOrder;
    @Bind(R.id.tv_noNetOrder)
    TextView tv_noNetOrder;
    @Bind(R.id.tv_noDownWindOrder)
    TextView tv_noDownWindOrder;
    @Bind(R.id.ll_rentCar_stroke)
    LinearLayout ll_rentCar_stroke;
    @Bind(R.id.ll_netCar_stroke)
    LinearLayout ll_netCar_stroke;
    @Bind(R.id.ll_downwindCar_stroke)
    LinearLayout ll_downwindCar_stroke;

    @Override
    protected CharSequence provideTitle() {
        return "行程";
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_stroke;
    }

    @Override
    public void initListeners() {

    }

    @Override
    public StrokePresenter createPresenter() {
        return new StrokePresenter();
    }

    @OnClick({R.id.rl_rent_car, R.id.rl_net_car, R.id.rl_downwind_car})
    protected void rl_OnClick(View view) {
        switch (view.getId()) {
            case R.id.rl_rent_car://出租车行程
                startActivity(StrokeAllActivity.class, new Bun().putString("tag", "1").ok());
                break;
            case R.id.rl_net_car://网约车行程
                startActivity(StrokeAllActivity.class, new Bun().putString("tag", "6").ok());
                break;
            case R.id.rl_downwind_car://顺风车行程
                startActivity(StrokeAllActivity.class, new Bun().putString("tag", "2").ok());
                break;
        }
    }

    @Override
    protected void initThings(Bundle savedInstanceState) {
        super.initThings(savedInstanceState);
        Map map = new HashMap();
        map.put("user_id", new UserUtil(this).getUserId());
        map.put("type", 1);
        map.put("car_type", 1);
        map.put("state", 101);
        map.put("nowpage", 0);
        map.put("page_num", 2);
        String json = StringUtil.toJson(map);
        try {
            String data1 = AESCrypt.getInstance().encrypt(json);
            String d = StringUtil.replaceBlank(data1);
            presenter.Stroke(d);
        } catch (Exception ex) {
        }
    }

    @Override
    public void StrokeSuccess(StrokeBean stroke) {
//        if(stroke.departure ==null){
//            tv_noRentOrder.setVisibility(View.VISIBLE);
//        }
//        tvRentCarDeparture.setText(stroke.departure);
//        tvRentCarDestination.setText(stroke.destination);
//        tvRentCarTime.setText(stroke.driver_accept_time);
    }

    @Override
    public void StrokeSuccess(ArrayList<StrokeBean> strokes) {
        StrokeBean rentStroke = strokes.get(0);//出租车行程
        if(rentStroke.departure ==null){
            tv_noRentOrder.setVisibility(View.VISIBLE);
            ll_rentCar_stroke.setVisibility(View.GONE);
        }else{
            tv_noRentOrder.setVisibility(View.GONE);
            ll_rentCar_stroke.setVisibility(View.VISIBLE);
            tvRentCarDeparture.setText(rentStroke.departure);
            tvRentCarDestination.setText(rentStroke.destination);
            tvRentCarTime.setText(rentStroke.driver_accept_time);
        }
        StrokeBean netStroke = strokes.get(1);//网约车行程
        if(netStroke.departure ==null){
            tv_noNetOrder.setVisibility(View.VISIBLE);
            ll_netCar_stroke.setVisibility(View.GONE);
        }else{
            tv_noNetOrder.setVisibility(View.GONE);
            ll_netCar_stroke.setVisibility(View.VISIBLE);
            tvNetCarDeparture.setText(netStroke.departure);
            tvNetCarDestination.setText(netStroke.destination);
            tvNetCarTime.setText(netStroke.driver_accept_time);
        }
        StrokeBean downwindStroke = strokes.get(2);//顺风车行程
        if(downwindStroke.departure ==null){
            tv_noDownWindOrder.setVisibility(View.VISIBLE);
            ll_downwindCar_stroke.setVisibility(View.GONE);
        }else{
            tv_noDownWindOrder.setVisibility(View.GONE);
            ll_downwindCar_stroke.setVisibility(View.VISIBLE);
            tvDownwindCarDeparture.setText(downwindStroke.departure);
            tvDownwindCarDestination.setText(downwindStroke.destination);
            tvDownwindCarTime.setText(downwindStroke.driver_accept_time);
        }
    }

    @Override
    public void StrokeError(String msg) {

    }

}
